import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:wan_android_flutter/common/base/base_controller.dart';
import 'package:wan_android_flutter/common/network/model/knowledges_model.dart';

import 'single_knowledge_system_state.dart';

class SingleKnowledgeSystemLogic extends BaseController with GetTickerProviderStateMixin {
  final SingleKnowledgeSystemState state = SingleKnowledgeSystemState();

  late final TabController tabController =
      TabController(initialIndex: 0, length: state.tabLocalKeyList.length, vsync: this);

  @override
  void onInit() {
    super.onInit();
    if (Get.arguments != null && Get.arguments is KnowledgeModel) {
      KnowledgeModel knowledgeModel = Get.arguments;
      state.title.value = knowledgeModel.name ?? "";
      state.knowledges.assignAll(knowledgeModel.children ?? []);
      List<String> titles = [];
      knowledgeModel.children?.forEach((element) {
        titles.add(element.name ?? "");
      });
      state.tabLocalKeyList.assignAll(titles);
    }
    tabController.addListener(() {
      state.currentTabIndex.value = tabController.index;
    });
  }
}
